#include <gtk/gtk.h>
#include <stdio.h>

#include "gtkutils.h"
#include "logs/log.h"

createSignalFunc(sayHello) {
    // INFO_LOG("window: %d, button: %d", GTK_IS_WINDOW(user_data), GTK_IS_BUTTON(widget));
    INFO_LOG("Hello Word -- Say");
}
createSignalSwappedFunc(sayExit){
    // INFO_LOG("window: %d, button: %d", GTK_IS_WINDOW(user_data), GTK_IS_BUTTON(widget));
    INFO_LOG("Hello Word -- Exit");
    closeWindow(user_data);
}

// 某某的信号调用某方法，并传入一个数据源，回调函数(某某对象[self]，数据源)
// g_signal_connect(instance, detailed_signal, c_handler, data)

// 某某的信号调用某方法，并传入一个数据源，回调函数(数据源，某某对象[被忽略])
// g_signal_connect_swapped(instance, detailed_signal, c_handler, data)

// 相比两种回调函数，传入的数据源[data]处于回调函数参数的不同位置

// [2021-08-18 10:52:50.185] I - window: 1, button: 1
// [2021-08-18 10:52:50.185] I - Hello Word -- Say
// [2021-08-18 10:52:50.185] I - window: 1, button: 1
// [2021-08-18 10:52:50.185] I - Hello Word -- Exit

static void activate(GtkApplication *app, gpointer user_data) {
    GtkWindow *window = createWindowWithTitleSize(app, "editor-tr", 200, 100);
    GtkButton *button = createButton("Hello World");

    connectButtonClickAndSwappedAction(window, button, sayHello, sayExit);

    setWindowChild(window, button);
    showWindow(window);
}

int	main(int argc, char **argv) {
    GtkApplication *app = createApplicationConnectActivate("editor.tr", 
                                                            G_APPLICATION_FLAGS_NONE, 
                                                            activate);
    int status = runApplication(app, argc, argv);
    objectUnref(app);
    return status;
}

// When Click 'Hello World' Button - Printf 'hello word' and exit this programe
// AppName: gtk-hello-word-test
// ┌────────────────────────────┐
// │         editor-tr          │
// ├────────────────────────────┤
// │┌──────────────────────────┐│
// ││                          ││
// ││        Hello World       ││
// ││                          ││
// │└──────────────────────────┘│
// └────────────────────────────┘

// Output:
// ┌────────────┐
// │ hello word │
// └────────────┘